/*
Uninclude: Tool for detecting unused #included files in C and C++ code.
    Copyright (C) 2012  Daniel Gutson, FuDePAN

    Uninclude is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version./

    Uninclude is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Uninclude.  If not, see <http://www.gnu.org/licenses/>.

    This is the includes tree file.
*/

#ifndef FILE_TREE_H
#define FILE_TREE_H

#include <stack>
#include "uninclude/file_node.h"
#include "uninclude/dir_utils.h"

class FilesTree
{
    stack<FileNode*> branch;
    RootNode root;

public:
    FilesTree(const string& rootName)
        : root(rootName)
    {
        //cerr << rootName << endl;
        branch.push(&root);
    }

    void pushFile(const string& fileName, size_t line)
    {
        //cerr << fileName << endl;        
        branch.push(branch.top()->addChild(fileName, line));
    }

    void popFile()
    {
        //cerr << " pop" << endl;
        if (branch.empty())
            throw "Error: returning to an inexistent file.";

        branch.pop();
    }

    void traverseAndCommentIncludes(NodeAPI* api)
    {
        root.commentIncludes(api);
    }

    string originalName() const
    {
        return root.getName();
    }

    string tmpName() const
    {
        return root.getTmpName();
    }
};

#endif

